package org.jash.shop2201

import androidx.databinding.ObservableInt
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.viewmodel.initializer
import androidx.lifecycle.viewmodel.viewModelFactory
import com.alibaba.android.arouter.launcher.ARouter
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import org.jash.shop2201.databinding.ActivityMainBinding
import org.jash.shop2201.mvvm.BaseActivity
import org.jash.shop2201.utils.StoreUtils

@AndroidEntryPoint
class MainActivity : BaseActivity<ActivityMainBinding, MainViewModel>() {
    val count by lazy { ObservableInt(2) }
    override fun initData() {
        if (StoreUtils.getBoolean("first", true)) {
            lifecycleScope.launch {
                for (i in count.get() downTo 0) {
                    count.set(i)
                    delay(1000)
                }
                StoreUtils.save("first", false)
                ARouter.getInstance().build("/shop/login").navigation()
                finish()
            }
        } else {
            ARouter.getInstance().build("/shop/login").navigation()
            finish()
        }
        viewModel.test()
    }

    override fun initView() {
        binding.count = count
    }
}